export { }
declare global {
  interface Array<T> {
    remove (...items: T[]): T[]
    removeBy (compare: (s: T, t: T) => boolean, ...items: T[]): T[]
  }
}

if (!Array.prototype.remove) {
  Object.defineProperty(Array.prototype, 'remove', {
    enumerable: false,
    writable: false,
    configurable: false,
    value: function remove<T> (this: T[], ...items: T[]): T[] {
      items.forEach((item) => {
        const idx = this.indexOf(item)
        if (idx > -1) {
          this.splice(idx, 1)
        }
      })
      return this
    },
  })
}

Object.defineProperty(Array.prototype, 'removeBy', {
  enumerable: false,
  writable: false,
  configurable: false,
  value: function remove<T> (this: T[], compare: (s: T, t: T) => boolean, ...items: T[]): T[] {
    items.forEach((item) => {
      const idx = this.findIndex(i => compare(i, item))
      if (idx > -1) {
        this.splice(idx, 1)
      }
    })
    return this
  },
})
